<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>注册审核</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/admin.css">
    <link rel="stylesheet" href="../css/examine.css">
    <link rel="stylesheet" href="../fonts/iconfont.css">
</head>
<style>
            .container{
                display: flex;
                background-color:#F3F3F3;
            }
            .detail{
                height:600px;
            }
            .layui-table[lay-skin=line] td, .layui-table[lay-skin=line] th{
                background-color:#fff;
            }
            .layui-table td, .layui-table th{
                padding:14px 15px;
            }
            form{
                float:left;
                margin-top:10px;
                display: inline-block;
            }
            .layui-layer-btn,.layui-layer-content{
                text-align:center;
            }
            #search_box{
                display:inline-block;
                margin-top:9px;
            }
            #search{
                display:inline-block;
                margin-top:9px;
            }
</style>
<body>
<div class="container">
    <!-- 列表-->
    <div class="section-right">
        <div class="right-top">
            <form class="layui-form" action="" style="border:1px solid #EF7632;border-radius:5px;">
                <select id="status" name="status"  lay-verify="required" lay-filter="test8">
                    <option value="">选择状态类型查询</option>
                    <option value="5">全部</option>
                    <option value="0">未付款</option>
                    <option value="1">已付款</option>
                    <option value="2">无需付款</option>
                    <option value="3">已审核</option>
                    <option value="4">已驳回</option>
                </select>
            </form>
            <div id="search" style="cursor: pointer; "><i class="layui-icon" style="font-size: 34px; color: #EF7632;">&#xe615;</i> </div>
            <button class="layui-btn layui-btn-normal  add right"><span class="pic-4 iconfont icon-shenhebiao"></span>数据审核</button>
        </div>
        <!--  table部分 -->
        <div class="detail">
            <table class="layui-table" lay-skin="line"  id="table">
                <thead>
                <tr>
                    <th></th>
                    <th>楼&nbsp;&nbsp;名</th>
                    <th>门牌号</th>
                    <th>用户账号</th>
                    <th>账号余额</th>
                    <th>收费模式</th>
                    <th>账号状态</th>
                    <th>审核状态</th>
                </tr>
                </thead>
                <tbody class="org-table">
                </tbody>
            </table>
            <div id="page-fen">
                <div id="page-num"></div>
            </div>
        </div>
    </div>
</div>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="../layui/layui.js"></script>
<script src="../lib/js/jquery.cookie.js" type="text/javascript"></script>
<script>
    layui.use(['jquery','form','layer','laypage','element'], function() {
        var $ = layui.jquery;
        var form = layui.form();
        var laypage = layui.laypage;
            layer = layui.layer;

        var user_id = localStorage.getItem("user_id");
        console.log(user_id);
        var params = {};
        form.render();
        $("#search").off("click").on("click", function () {
            if(params.statusValue){
               var valAll = params.statusValue.split(",")
                   console.log(valAll);
                   dataAll = valAll;
            }
            searchTable();
        })

        var dataAll = new Array("0", "1", "2", "3", "4","5");


            form.on('select(test8)', function (data) {
                var statusValue = data.value;
                var statusName = data.elem[data.elem.selectedIndex].text;
                params.statusValue = statusValue;
                params.statusName = statusName;
                console.log('params.statusValue', params.statusValue);
                console.log('params.statusName', params.statusName);
            });

        fixData();
        function fixData(currentData){
            $(".right").off("click").on("click",  function() {
                console.log(currentData);
                if(currentData){
                    layer.open({

                        shade:[0.1, '#fff']

                        ,title:['信息审核','font-weight:600;text-align:center;font-size:16px;border-radius:10px;']
                        ,content: '是否通过审核？'
                        ,btn: ['是', '否']
                        ,yes: function(index, layero){
                            var id = currentData.id;
                            console.log(id);
                            console.log(index);
                            console.log(layero);
                            $.ajax({
                                url: '../../organization_manage/check',
                                type: 'get',
                                dataType: 'json',
                                data:{
                                    id :id,
                                    type:3,
                                    phone: currentData.telphone
                                }
                            })
                                .done(function(response) {
                                    console.log("success",response);
                                    window.location.reload();
                                    layer.closeAll();
                                })
                                .fail(function(response) {
                                    console.log("error",response);
                                    window.location.reload();
                                    layer.closeAll();
                                });
                        }
                        ,btn2: function(index, layero){
                            var id = currentData.id;
                            console.log(index);
                            console.log(layero);
                            $.ajax({
                                url: '../../organization_manage/check',
                                type: 'get',
                                dataType: 'json',
                                data:{
                                    id :id,
                                    type:4
                                }
                            })
                                .done(function(response) {
                                    console.log("success");
                                    window.location.reload();
                                    layer.closeAll();
                                })
                                .fail(function(response) {
                                    console.log("error",response);
                                    window.location.reload();
                                    layer.closeAll();
                                });
                        }
                    })
                }else{
                    alert("请先选中一条数据");
                }
            });
        };
        var pages = {};
        searchTable();
        function searchTable(current_page){
        $.ajax({
            url: '../../organization_manage/getCheckList',
            traditional: true,
            type: 'get',
            dataType: 'json',
            data: {
                wuye_id: user_id,
                type: dataAll,
                current_page:current_page || 1,
                limit:10
            }
        })
            .done(function (response) {
                console.log(response);
                var data = response.page.list;

                if (response.resultCode == 200) {
                    var str = '';
                    if (response.page.list.length) {

                        for (var i = 0; i < response.page.list.length; i++) {
                            var status_ac = "";
                            var status = "";
                            if(data[i].checked == 0){
                                status_ac +=
                                    '<span style="">'+"未付款"+'<span>'
                                status +=
                                    '<span style="">'+"待处理"+'<span>'
                            }else if(data[i].checked == 1){
                                status_ac +=
                                    '<span style="">'+"已付款"+'<span>'
                                status +=
                                    '<span style="">'+"待处理"+'<span>'
                            }else if(data[i].checked == 2){
                                status_ac +=
                                    '<span style="">'+"无需付款"+'<span>'
                                status +=
                                    '<span style="">'+"待处理"+'<span>'
                            }else if(data[i].checked == 3){
                                status_ac +=
                                    '<span style="color:#B8664D">'+"已审核"+'<span>'
                                status +=
                                    '<span style="color:#B8664D">'+"已处理"+'<span>'
                            }else if(data[i].checked == 4){
                                status_ac +=
                                    '<span style="color:#52689F">'+"已驳回"+'<span>'
                                status +=
                                    '<span style="color:#B8664D">'+"已处理"+'<span>'
                            };
                            if(data[i].is_charge == 0){
                                var lift_charge = "乘梯免费";
                            }else if(data[i].is_charge == 1){
                                var lift_charge = "乘梯付费";
                            };
                            str +=
                                '<tr data-id="' + data[i].id + '">' +
                                '<td class="check"><input type="checkbox" name="items" title="" lay-skin="primary" data-id="' + data[i].id + '"></td>' +
                                '<td>' + data[i].building_name + '</td>' +
                                '<td>' + data[i].menpaihao + '</td>' +
                                '<td>' + data[i].telphone + '</td>' +
                                '<td>' + data[i].balance + '</td>' +
                                '<td>' + lift_charge + '</td>' +
                                '<td>' + status_ac + '</td>' +
                                '<td>' + status + '</td>' +
                                '</tr>'
                        }
                        $(".org-table").html(str);
                        form.render();
                        show();
                        //选中当前行
                        $("#table>tbody>tr>td>input").change(function () {
                            console.log("当前行状态改变");
                            if ($(this).is(':checked')) {

                                var currentId = $(this).attr("data-id");
                                for (var i = 0; i < data.length; i++) {
                                    if (data[i].id == currentId) {
                                        var currentData = data[i];

                                        fixData(currentData);
                                    }
                                }
                            } else {
                                var currentId = '';
                            }
                            console.log(currentId);
                            params.id = currentId;

                        });//选中tr

                        pages.total = response.page.total;
                        pages.current_page = response.page.current_page;
                        pages.totalPages = Math.ceil(pages.total/10);
                        /*显示分页*/
                        laypage({
                            cont: 'page-num'
                            ,pages: pages.totalPages     //通过后台拿到的总页数
                            // skip: true, 是否开启跳页
                            ,curr: pages.current_page  //当前页
                            ,first: false
                            ,last:false
                            ,prev: '<em><</em>'
                            ,next: '<em>></em>'
                            ,jump: function(obj, first){ //触发分页后的回调
                                var curr = obj.curr;
                                console.log(curr);
                                if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
                                    searchTable(obj.curr);
                                }
                            }
                        })
                    }
                    else {
                        str = '<tr><td colspan="7">暂无数据</td></tr>';
                        $(".org-table").html(str);
                        hidden();
                    }
                }//200
            })//done
            .fail(function (response) {
                console.log("fail", response);
                if (response.resultCode == '001') {
                    console.log("param is not found");
                } else if (response.resultCode == '009') {
                    console.log("String is not int type");
                }
            })//fail
         }
        //审核
        function show(){
            document.getElementById("page-fen").style.display="";
        };
        function hidden(){
            document.getElementById("page-fen").style.display="none";
        };

    });//模块加载
</script>
</body>
</html>
